package backup;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.TextEvent;
import java.awt.event.TextListener;

import org.dvb.ui.DVBColor;
import org.havi.ui.HContainer;
import org.havi.ui.event.HRcEvent;

import device.DeviceHelper;

public class DeviceRegister extends HContainer implements KeyListener {

    private Panel panel;

    private final MainMenu mainMenu;

    private final Render render;

    public DeviceRegister(int i, int j, int k, int l, MainMenu mainMenu) {
        this.mainMenu = mainMenu;
        render = new Render();
        this.addKeyListener(this);
        //Componentes();
        panel = new TesteRegister();
        this.add(panel);
        this.setBackground(new DVBColor(0, 255, 0, 100));
        panel.repaint();
        repaint();
    }

    private void Componentes() {
        panel = new Panel();
        panel.setSize(500, 500);
        panel.setBackground(Color.WHITE);
        panel.setLocation(115, 45);
        panel.setLayout(new FlowLayout());

        render.getLabel("Cadastro de Equipamentos", panel);

        Panel p1 = render.getPanel(new GridLayout(5, 5), panel);

        render.getLabel("Nome", p1);

        TextField text = render.getTextField(p1);
        text.addFocusListener(new FocusListener() {

            public void focusLost(FocusEvent e) {
                System.out.println("perdeu foco");
            }

            public void focusGained(FocusEvent e) {
                System.out.println("ganhou foco");
            }
        });
        text.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                System.out.println("sadas");
            }
        });
        text.addTextListener(new TextListener() {

            public void textValueChanged(TextEvent e) {
                System.out.println("sadas");
            }
        });

        render.getLabel("Host", p1);

        text = render.getTextField(p1);

        render.getLabel("Porta", p1);

        text = render.getTextField(p1);

        render.getButton("Gravar", p1, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                System.out.println("OK");
                DeviceRegister.this.requestFocus();
            }
        });

        render.getButton("Voltar", p1, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                System.out.println("Voltou");
                mainMenu.removePanelScene(DeviceRegister.this);
            }
        });

        render.getCombo(DeviceHelper.getInstance().getDevicesNames(), p1);

    }

    public void keyPressed(KeyEvent e) {
        if (e.getKeyChar() == HRcEvent.VK_LEFT) {} else if (e.getKeyChar() == HRcEvent.VK_RIGHT) {} else if (e.getKeyChar() == HRcEvent.VK_ESCAPE) {
            mainMenu.removePanelScene(this);
        }

    }

    public void keyReleased(KeyEvent e) {
    // TODO Auto-generated method stub

    }

    public void keyTyped(KeyEvent e) {
    // TODO Auto-generated method stub

    }

}
